package com.demo2do.fms.admin.dao.vehicle;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.vehicle.source.LockStatus;
import com.demo2do.fms.entity.vehicle.source.VehicleSourceLockRecord;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface VehicleLockRecordDao {
    
    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM VehicleSourceLockRecord WHERE vehicleSource.disabled = false")
    public int count();
    
    /**
     * @param status
     * @return
     */
    @Query("SELECT COUNT(*) FROM VehicleSourceLockRecord WHERE status = :status AND vehicleSource.disabled = false")
    public int count(@Variable("status") LockStatus status);
    
    /**
     * 
     * @param supplierId
     * @return
     */
    @Query("SELECT COUNT(*) FROM VehicleSourceLockRecord WHERE vehicleSource.supplier.id = :supplierId AND vehicleSource.disabled = false")
    public int count(@Variable("supplierId") Long supplierId);
    
    /**
     * 
     * @param status
     * @param supplierId
     * @return
     */
    @Query("SELECT COUNT(*) FROM VehicleSourceLockRecord WHERE status = :status AND vehicleSource.supplier.id = :supplierId AND vehicleSource.disabled = false")
    public int count(@Variable("status") LockStatus status, @Variable("supplierId") Long supplierId);
    
    /**
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM VehicleSourceLockRecord WHERE vehicleSource.disabled = false ORDER BY createTime DESC")
    public List<VehicleSourceLockRecord> list(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM VehicleSourceLockRecord WHERE status = :status AND vehicleSource.disabled = false ORDER BY createTime DESC")
    public List<VehicleSourceLockRecord> list(@Variable("status") LockStatus status, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param supplierId
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM VehicleSourceLockRecord WHERE vehicleSource.supplier.id = :supplierId AND vehicleSource.disabled = false ORDER BY createTime DESC")
    public List<VehicleSourceLockRecord> list(@Variable("supplierId") Long supplierId, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param status
     * @param supplierId
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM VehicleSourceLockRecord WHERE status = :status AND vehicleSource.supplier.id = :supplierId AND vehicleSource.disabled = false ORDER BY createTime DESC")
    public List<VehicleSourceLockRecord> list(@Variable("status") LockStatus status, @Variable("supplierId") Long supplierId, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

}
